#include "ins_receive.h"
#include "main.h"

#include "CAN_receive.h"

#include <string.h>

ins_receive_t ins_data;    //INS姿态数据
uint8_t ins_data_receive_buff[24];   //缓存数据

void ins_receive(CAN_RxHeaderTypeDef rx_header,uint8_t rx_data[8])  //INS接收函数
{
    if(rx_header.StdId == CAN_INS_ID1 && ins_data.ins_receive_state_flag == INS_FLAME_THREE_DONE)
    {
        memcpy(&ins_data_receive_buff[0],rx_data,sizeof(uint64_t));
        ins_data.ins_receive_state_flag = INS_FLAME_ONE_DONE;
    }
    else if(rx_header.StdId == CAN_INS_ID2 && ins_data.ins_receive_state_flag == INS_FLAME_ONE_DONE)
    {
        memcpy(&ins_data_receive_buff[8],rx_data,sizeof(uint64_t));
        ins_data.ins_receive_state_flag = INS_FLAME_TWO_DONE;
    }
    else if(rx_header.StdId == CAN_INS_ID3 && ins_data.ins_receive_state_flag == INS_FLAME_TWO_DONE)
    {
        memcpy(&ins_data_receive_buff[16],rx_data,sizeof(uint64_t));
        memcpy(ins_data.ins_data.uint8,ins_data_receive_buff,sizeof(ins_data_receive_buff));
        ins_data.ins_receive_state_flag = INS_FLAME_THREE_DONE;
    }
    else
    {
        ins_data.ins_receive_state_flag = INS_FLAME_THREE_DONE;
    }
}

const fp32 *get_gyro_data_point(void)  
{
    return ins_data.ins_data.fp32.gyro;    //INS姿态数据
}

const fp32 *get_angle_data_point(void)  
{
    return ins_data.ins_data.fp32.angle;
}
